<template>
  <div class="app-container">
    <div class="card-wrap padding20 flex">
      <div v-for="(item, index) in tabs" :key="index" @click="tabClick(index)" :class="item.check ? 'tab-active' : 'tab-normal'">
        {{ item.name }}
      </div>
    </div>
    <SearchContent :queryParams="queryParams" @query="handleQuery" @reset="resetQuery">
      <el-col :span="6">
        <el-form-item label="车牌号/车架号:" prop="carNoVinNo">
          <el-input maxlength="30" v-model="queryParams.carNoVinNo" clearable placeholder="请输入车牌号/车架号"></el-input>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="品牌/车系/车型:" prop="modelId">
          <linkage-select v-model="linkageList" placeholder="请选择品牌/车系/车型" :check-strictly="false" style="width: 100%" @changeNode="linkageChange" />
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="车辆产权:" prop="propertyRightName">
          <el-select placeholder="请选择车辆产权" filterable v-model="queryParams.propertyRightName" clearable style="width: 100%">
            <template v-for="(item, index) in companyOriginList">
              <el-option :label="item.deptName" :value="item.deptName" :key="index"></el-option>
            </template>
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="车辆归属:" prop="ascriptionId">
          <el-select placeholder="请选择车辆归属" filterable @change="belongChange" v-model="queryParams.ascriptionId" clearable style="width: 100%">
            <template v-for="(item, index) in belongCompanyList">
              <el-option :label="item.deptName" :value="item.deptId" :key="index"></el-option>
            </template>
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="车辆大区:" prop="cityId">
          <RegionCityLink v-model="queryParams.citydata" placeholder="请选择车辆大区" ref="citySelect" :showAllLevels="false" :defaultSelect="selIds" @change="citySelectionChange"></RegionCityLink>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="车辆运营城市:" prop="operationsName">
          <el-input maxlength="30" v-model="queryParams.operationsName" clearable placeholder="请输入运营城市"></el-input>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="产品类型:" prop="contractType">
          <el-select placeholder="请选择产品类型" filterable v-model="queryParams.contractType" clearable>
            <template v-for="dict in dict.type.quota_rent_type">
              <el-option :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
            </template>
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="车辆状态:" prop="businessType">
          <el-select placeholder="请选择车辆状态" filterable v-model="queryParams.businessType" clearable>
            <!--            <el-option v-for="item in businessTypeList" :key="item.value" :label="item.label" :value="item.value">-->
            <!--            </el-option>-->
            <template v-for="dict in dict.type.car_business_type">
              <el-option :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
            </template>
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="GPS工单类型:" prop="gpsType">
          <el-select placeholder="请选择工单类型" filterable v-model="queryParams.gpsType" clearable>
            <template v-for="dict in dict.type.gps_workorder_type">
              <el-option :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
            </template>
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="GPS品牌:" prop="gpsBrand">
          <el-input maxlength="30" v-model="queryParams.gpsBrand" clearable placeholder="请输入GPS品牌"></el-input>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="客户名称:" prop="customerName">
          <el-input maxlength="30" v-model="queryParams.customerName" clearable placeholder="请输入客户名称"></el-input>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="报警类型:" prop="alarmType">
          <el-select placeholder="请选择报警类型" filterable v-model="queryParams.alarmType" clearable>
            <template v-for="dict in dict.type.gps_alarm_type">
              <el-option :label="dict.label" :value="dict.label" :key="dict.label"></el-option>
            </template>
          </el-select>
        </el-form-item>
      </el-col>

      <!--            <el-col :span="24">-->
      <!--                <el-form-item label="查询时间:">-->
      <!--                    <ShortcutDate @isButIdx="isButIdx"-->
      <!--                                  v-model="checked" @dateChangeType="changeShortcutDate">-->

      <!--                        <el-date-picker v-model="dateValue" type="daterange" range-separator="-"-->
      <!--                                        start-placeholder="开始日期" unlink-panels-->
      <!--                                        end-placeholder="结束日期" value-format='yyyy-MM-dd' clearable-->
      <!--                                        @change='changeDate'>-->
      <!--                        </el-date-picker>-->

      <!--                    </ShortcutDate>-->
      <!--                </el-form-item>-->
      <!--            </el-col>-->
    </SearchContent>

    <div class="card-wrap card-padding">
      <div class="table-title-wrap justify-end">
        <el-button type="primary" size="mini" @click="handleExport" v-hasPermi="['GPSManage:GPSMonitorManage:export']">导出 </el-button>
      </div>

      <table-page :loading="loading" :dataList="dataList" border :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @setSizeCurrent="getList">
        <!-- 操作插槽 -->
        <template slot="tableColAc">
          <el-table-column min-width="130" label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <e-button size="mini" type="text" @click="handleDetail(scope.row)" v-hasPermi="['GPSManage:GPSMonitorManage:view']">查看 </e-button>
              <e-button size="mini" type="text" @click="handleDelete(scope.row)" v-hasPermi="['GPSManage:GPSMonitorManage:delete']">删除 </e-button>
            </template>
          </el-table-column>
        </template>
        <!-- 普通列插槽 -->
        <template slot="tableCol">
          <el-table-column show-overflow-tooltip min-width="210" label="车辆产权" align="center" prop="propertyRightName">
            <template v-slot="{ row }">
              {{ row.propertyRightName | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="210" label="车辆归属" align="center" prop="ascription">
            <template v-slot="{ row }">
              {{ row.ascription | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="115" label="车辆大区" align="center" prop="region">
            <template v-slot="{ row }">
              {{ row.region | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="115" label="车辆运营城市" align="center" prop="operationsName">
            <template v-slot="{ row }">
              {{ row.operationsName | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="115" label="车牌号" align="center" prop="carNo">
            <template v-slot="{ row }">
              {{ row.carNo | filterNull }}
              <!--                            <e-button size="mini" type="text">{{row.carNo|filterNull}}-->
              <!--                            </e-button>-->
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="190" label="车架号" align="center" prop="vinNo">
            <template v-slot="{ row }">
              {{ row.vinNo | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="310" label="品牌/车系/车型" align="center" prop="brandName">
            <template v-slot="{ row }"> {{ row.brandName | filterNull }}/{{ row.seriesName | filterNull }}/{{ row.modelName | filterNull }} </template>
          </el-table-column>

          <el-table-column show-overflow-tooltip min-width="115" label="客户名称" align="center" prop="customerName">
            <template v-slot="{ row }">
              {{ row.customerName | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="115" label="客户类型" align="center" prop="customerType">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.customer_type" :value="scope.row.customerType" />
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="115" label="客户等级" align="center" prop="customerLevel">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.customer_level" :value="scope.row.customerLevel" />
            </template>
          </el-table-column>

          <el-table-column show-overflow-tooltip min-width="115" label="车辆状态" align="center" prop="businessType">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.car_business_type" :value="scope.row.businessType" />
            </template>
          </el-table-column>
<!--          <el-table-column show-overflow-tooltip min-width="115" label="产品类型" align="center" prop="productType">-->
<!--            &lt;!&ndash; <template slot-scope="scope">-->
<!--              <dict-tag :options="dict.type.quota_rent_type" :value="scope.row.productType" />-->
<!--            </template> &ndash;&gt;-->
<!--            <template v-slot="{ row }">-->
<!--              {{ row.productType | filterNull }}-->
<!--            </template>-->
<!--          </el-table-column>-->

          <el-table-column show-overflow-tooltip min-width="115" label="联系人" align="center" prop="primaryContact">
            <template v-slot="{ row }">
              {{ row.primaryContact | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="150" label="联系电话" align="center" prop="primaryContactPhone">
            <template v-slot="{ row }">
              {{ row.primaryContactPhone | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="90" label="产品类型" align="center" prop="contractType">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.quota_rent_type" :value="scope.row.contractType" />
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="150" label="合同实际开始日期" align="center" prop="contractStartTime">
            <template v-slot="{ row }">
              {{ row.contractStartTime | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="150" label="合同实际结束日期" align="center" prop="contractEndTime">
            <template v-slot="{ row }">
              {{ row.contractEndTime | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="90" label="GPS品牌" align="center" prop="gpsBrand">
            <template v-slot="{ row }">
              {{ row.gpsBrand | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="90" label="设备类型" align="center" prop="equipmentType">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.gps_device_type" :value="scope.row.equipmentType" />
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="115" label="合同签订公里数" align="center" prop="contractSignKm">
            <template v-slot="{ row }">
              {{ row.contractSignKm | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="115" label="车辆初始公里数" align="center" prop="initialKm">
            <template v-slot="{ row }">
              {{ row.initialKm | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="115" label="实时公里数" align="center" prop="realTimeKm">
            <template v-slot="{ row }">
              {{ row.realTimeKm | filterNull }}
            </template>
          </el-table-column>

          <el-table-column show-overflow-tooltip min-width="115" label="日均里程" align="center" prop="dailyMileage">
            <template v-slot="{ row }">
              {{ row.dailyMileage | filterNull }}
            </template>
          </el-table-column>

          <el-table-column show-overflow-tooltip min-width="130" label="GPS设备状态" align="center" prop="gpsState">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.gps_state" :value="scope.row.gpsState" />
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="190" label="GPS设备编号" align="center" prop="equipmentNo">
            <template v-slot="{ row }">
              {{ row.equipmentNo | filterNull }}
            </template>
          </el-table-column>

          <el-table-column show-overflow-tooltip min-width="130" label="GPS设备安装时间" align="center" prop="gpsStartTime">
            <template v-slot="{ row }">
              {{ row.gpsStartTime | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="130" label="GPS设备结束时间" align="center" prop="gpsEndTime">
            <template v-slot="{ row }">
              {{ row.gpsEndTime | filterNull }}
            </template>
          </el-table-column>

          <el-table-column show-overflow-tooltip min-width="90" label="离线设备" align="center" prop="offLineEquipment">
            <template slot-scope="scope">
              {{ '0' === scope.row.offLineEquipment ? '有线' : '1' === scope.row.offLineEquipment ? '无线' : '2' === scope.row.offLineEquipment ? '有线+无线' : '未提供' }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="130" label="双离是否超过7天" align="center" prop="isDoubleOffLine">
            <template slot-scope="scope">
              {{ 0 == scope.row.isDoubleOffLine ? '否' : 1 == scope.row.isDoubleOffLine ? '是' : '未提供' }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="130" label="状态持续时长" align="center" prop="dismantleTime">
            <template v-slot="{ row }">
              {{ row.dismantleTime | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="190" label="离线原因" align="center" prop="offLineCause">
            <template v-slot="{ row }">
              {{ row.offLineCause | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="90" label="是否报警" align="center" prop="isAlarm">
            <template slot-scope="scope">
              {{ 0 == scope.row.isAlarm ? '否' : 1 == scope.row.isAlarm ? '是' : '--' }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="90" label="报警类型" align="center" prop="alarmType">
            <template slot-scope="scope">
              <!--              <dict-tag :options="dict.type.gps_alarm_type" :value="scope.row.alarmType" />-->
              {{ scope.row.alarmType | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="150" label="报警时间" align="center" prop="alarmTime">
            <template v-slot="{ row }">
              {{ row.alarmTime | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="190" label="最终定位地址" align="center" prop="finalLocatorAddress">
            <template v-slot="{ row }">
              {{ row.finalLocatorAddress | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="190" label="设备报装地点" align="center" prop="equipmentInstallAddress">
            <template v-slot="{ row }">
              {{ row.equipmentInstallAddress | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="150" label="是否已设置电子围栏" align="center" prop="isSettingsRail">
            <template v-slot="{ row }">
              {{ 0 == row.isSettingsRail ? '否' : 1 == row.isSettingsRail ? '是' : '未提供' }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="190" label="围栏设定地点" align="center" prop="settingsRailAddress">
            <template v-slot="{ row }">
              {{ row.settingsRailAddress | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="115" label="围栏设定城市" align="center" prop="settingsRailCity">
            <template v-slot="{ row }">
              {{ row.settingsRailCity | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="115" label="围栏是否跨省" align="center" prop="isRailTransProvincial">
            <template v-slot="{ row }">
              {{ 0 == row.isRailTransProvincial ? '否' : 1 == row.isRailTransProvincial ? '是' : '未提供' }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="150" label="跨区时间" align="center" prop="latestWarningTime">
            <template v-slot="{ row }">
              {{ row.latestWarningTime | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="115" label="是否出围栏" align="center" prop="isOutRail">
            <template v-slot="{ row }">
              {{ 0 == row.isOutRail ? '否' : 1 == row.isOutRail ? '是' : '--' }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="170" label="出围栏地点据围栏地距离" align="center" prop="outRailAddressDistance">
            <template v-slot="{ row }">
              {{ row.outRailAddressDistance | filterNull }}
            </template>
          </el-table-column>

          <el-table-column show-overflow-tooltip min-width="130" label="最新跨区预警时间" align="center" prop="latestWarningTime">
            <template v-slot="{ row }">
              {{ row.latestWarningTime | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="100" label="跨区预警次数" align="center" prop="numberWarning">
            <template v-slot="{ row }">
              {{ row.numberWarning | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="100" label="当前跨区省份" align="center" prop="currentCrossProvince">
            <template v-slot="{ row }">
              {{ row.currentCrossProvince | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="100" label="当前跨区城市" align="center" prop="currentCrossProvinceCity">
            <template v-slot="{ row }">
              {{ row.currentCrossProvinceCity | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="100" label="跨区等级" align="center" prop="crossRegionalHierarchy">
            <template v-slot="{ row }">
              {{ row.crossRegionalHierarchy | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="130" label="最新黑区驶入时间" align="center" prop="latestBlackXZoneEntryTime">
            <template v-slot="{ row }">
              {{ row.latestBlackXZoneEntryTime | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="130" label="最新黑区驶出时间" align="center" prop="latestBlackZoneExitTime">
            <template v-slot="{ row }">
              {{ row.latestBlackZoneExitTime | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="80" label="黑区预警次数" align="center" prop="blackZoneWarningTimes">
            <template v-slot="{ row }">
              {{ row.blackZoneWarningTimes | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="100" label="在租客户租赁期间总里程" align="center" prop="totalMileageDuring">
            <template v-slot="{ row }">
              {{ row.totalMileageDuring | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="100" label="上一个月里程" align="center" prop="lastMonthMileage">
            <template v-slot="{ row }">
              {{ row.lastMonthMileage | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="100" label="上一周里程" align="center" prop="lastWeekMileage">
            <template v-slot="{ row }">
              {{ row.lastWeekMileage | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="100" label="出车频率" align="center" prop="departureFrequency">
            <template v-slot="{ row }">
              {{ row.departureFrequency | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="100" label="运营频次" align="center" prop="frequencyOfOperation">
            <template v-slot="{ row }">
              {{ row.frequencyOfOperation | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="100" label="评分" align="center" prop="mark">
            <template v-slot="{ row }">
              {{ row.mark | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="100" label="风险等级" align="center" prop="riskLevel">
            <template v-slot="{ row }">
              {{ row.riskLevel | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="100" label="高风险项" align="center" prop="highRiskItem">
            <template v-slot="{ row }">
              {{ row.highRiskItem | filterNull }}
            </template>
          </el-table-column>

          <el-table-column show-overflow-tooltip min-width="190" label="出围栏地点" align="center" prop="outRailAddress">
            <template v-slot="{ row }">
              {{ row.outRailAddress | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="115" label="出围栏城市" align="center" prop="outRailCity">
            <template v-slot="{ row }">
              {{ row.outRailCity | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="130" label="是否继续排查" align="center" prop="isTroubleshoot">
            <template v-slot="{ row }">
              {{ 0 == row.isTroubleshoot ? '否' : 1 == row.isTroubleshoot ? '是' : '--' }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="150" label="排查反馈时间" align="center" prop="troubleshootFeedbackTime">
            <template v-slot="{ row }">
              {{ row.troubleshootFeedbackTime | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="130" label="车辆状态" align="center" prop="troubleshootFeedbackCause">
            <template v-slot="{ row }">
              <dict-tag :options="dict.type.car_business_type" :value="row.businessType" />
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="190" label="排查反馈原因" align="center" prop="troubleshootFeedbackCause">
            <template v-slot="{ row }">
              {{ row.troubleshootFeedbackCause | filterNull }}
            </template>
          </el-table-column>

          <el-table-column show-overflow-tooltip min-width="100" label="排查人" align="center" prop="inspector">
            <template v-slot="{ row }">
              {{ row.inspector | filterNull }}
            </template>
          </el-table-column>

          <el-table-column show-overflow-tooltip min-width="115" label="平均日公里数" align="center" prop="averageNumberOfKilometersPerDay">
            <template v-slot="{ row }">
              {{ row.averageNumberOfKilometersPerDay | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="115" label="当日公里数" align="center" prop="kilometersOfTheDay">
            <template v-slot="{ row }">
              {{ row.kilometersOfTheDay | filterNull }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="185" label="安装>15天月里程<300km" align="center" prop="isInstallGreaterFifteenDayLessThreeHundredKm">
            <template v-slot="{ row }">
              {{ 0 == row.isInstallGreaterFifteenDayLessThreeHundredKm ? '否' : 1 == row.isInstallGreaterFifteenDayLessThreeHundredKm ? '是' : '未提供' }}
            </template>
          </el-table-column>
        </template>
      </table-page>
    </div>
  </div>
</template>

<script>
import SearchContent from '@/components/SearchContent/index.vue'
import LinkageSelect from '@/views/components/linkageSelect.vue'
import CitySelect from '@/views/components/citySelect.vue'
import ShortcutDate from '@/views/components/ShortcutDate/index.vue'
import { listDept } from '@/api/system/dept'
import RegionCityLink from '@/views/components/provinceCity/regionCityLink.vue'
import { carGpsMonitorList, carGpsMonitorDel } from '@/api/gps/gpsList'

export default {
  name: 'GPSMonitorList',
  components: {
    RegionCityLink,
    ShortcutDate,
    CitySelect,
    LinkageSelect,
    SearchContent,
  },
  dicts: ['gps_alarm_type', 'quota_rent_type', 'gps_workorder_type', 'gps_work_order_progress', 'vehicle_category', 'gps_device_type', 'customer_type', 'customer_level', 'gps_state', 'car_business_type'],
  data() {
    return {
      tabs: [
        {
          name: '当前数据',
          count: 0,
          check: true,
        },
        {
          name: '历史数据查询',
          count: 0,
          check: false,
        },
      ],
      checked: '',
      companyOriginList: [],
      dateValue: [],
      citySelection: [],
      //按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        isHistoryData: 0,
        carNoVinNo: null,
        brandId: null,
        seriesId: null,
        modelId: null,
        brandName: null,
        seriesName: null,
        modelName: null,
        propertyRightId: null,
        propertyRightName: null,
        ascriptionId: null,
        ascription: null,
        regionId: null,
        region: null,
        provinceName: null,
        provinceId: null,
        cityId: null,
        cityName: null,
        operationsName: null,
        gpsWorkProgress: null,
        // companyName:null,
        contractType: null,
        businessType: null,
        gpsType: null,
        gpsBrand: null,
        customerName: null,
        alarmType: null,
        queryStartTime: null,
        queryEndTime: null,
        citydata: [],
      },

      total: 0,
      dataList: [],
      belongCompanyList: [],
      selIds: [],
      linkageList: [],
    }
  },
  created() {
    this.getList()
    this.getCompanyOrigin()
  },
  activated() {
    this.getList()
    this.getCompanyOrigin()
  },
  methods: {
    getBusinessType(type) {
      return (
        this.businessTypeList.find((item) => {
          return item.value == type
        })?.label ?? '--'
      )
    },
    /** 查询测试单表列表 */
    getList() {
      this.loading = true
      this.queryParams.queryStartTime = this.dateValue && this.dateValue[0] ? this.dateValue[0] : ''
      this.queryParams.queryEndTime = this.dateValue && this.dateValue[1] ? this.dateValue[1] : ''

      carGpsMonitorList(this.queryParams).then((res) => {
        if (res.code == '200') {
          const { rows, total } = res
          this.dataList = rows
          this.total = total
          this.loading = false
        }
      })
    },
    tabClick(index) {
      this.tabs.forEach((item, i) => {
        item.check = index == i
      })

      this.queryParams.isHistoryData = index

      this.handleQuery()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.timeRange = []
      ;(this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        isHistoryData: 0,
        carNoVinNo: null,
        brandId: null,
        seriesId: null,
        modelId: null,
        brandName: null,
        seriesName: null,
        modelName: null,
        propertyRightId: null,
        propertyRightName: null,
        ascriptionId: null,
        ascription: null,
        regionId: null,
        region: null,
        provinceName: null,
        provinceId: null,
        cityId: null,
        cityName: null,
        operationsName: null,
        gpsWorkProgress: null,
        // companyName:null,
        contractType: null,
        businessType: null,
        gpsType: null,
        gpsBrand: null,
        customerName: null,
        alarmType: null,
        queryStartTime: null,
        queryEndTime: null,
        citydata: [],
      }),
        (this.checked = -1)
      this.selIds = []
      this.citySelection = []
      this.dateValue = []
      this.linkageList = []
      this.citySelectionChange([])
      // this.resetForm("queryForm");
      this.handleQuery()
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download(
        '/car/carGpsMonitoring/export',
        {
          ...this.queryParams,
        },
        `GPS监控管理.xlsx`
      )
    },
    handleDetail(row) {
      this.$router.push({
        name: 'GPSMonitorDetail',
        query: { carId: row.carId },
      })
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal
        .confirm('确定删除？')
        .then(() => {
          this.loading = true
          return carGpsMonitorDel(row.gpsMonitoringId)
        })
        .then(() => {
          this.loading = false
          this.handleQuery()
          this.$modal.msgSuccess('删除成功')
        })
        .finally(() => {
          this.loading = false
        })
    },

    isButIdx(idx) {
      this.checked = idx
      // this.dateValue = [];
    },
    changeDate(val) {
      this.checked = -1
      if (val) {
        this.queryParams.queryStartTime = val[0]
        this.queryParams.queryEndTime = val[1]
      } else {
        this.queryParams.queryStartTime = ''
        this.queryParams.queryEndTime = ''
      }
    },
    changeShortcutDate(val) {
      if (val) {
        this.dateValue = val
        this.queryParams.queryStartTime = val[0]
        this.queryParams.queryEndTime = val[1]
      } else {
        this.queryParams.queryStartTime = ''
        this.queryParams.queryEndTime = ''
      }
      console.log('changeShortcutDate', val, this.queryParams)
      // this.dateValue = []
      // this.queryParams.violationStartTime = val[0]
      // this.queryParams.violationEndTime = val[1]
      // this.getList()
    },

    async linkageChange(val) {
      this.linkageList = val
      if (val) {
        this.queryParams.brandId = val[0] ? val[0].id : ''
        this.queryParams.seriesId = val[1] ? val[1].id : ''
        this.queryParams.modelId = val[2] ? val[2].id : ''
        this.queryParams.brandName = val[0] ? val[0].name : ''
        this.queryParams.seriesName = val[1] ? val[1].name : ''
        this.queryParams.modelName = val[2] ? val[2].name : ''
      } else {
        this.queryParams.brandId = null
        this.queryParams.seriesId = null
        this.queryParams.modelId = null
        this.queryParams.brandName = null
        this.queryParams.seriesName = null
        this.queryParams.modelName = null
      }
      this.$forceUpdate()
    },

    getCompanyOrigin() {
      listDept({
        deptType: '2', //组织类型（1部门 2公司）
        regionId: null, //所在城市（省市区id）
      }).then((res) => {
        this.companyOriginList = res.data
        this.belongCompanyList = res.data
      })
    },

    getBelongCompany() {
      listDept({
        deptType: '2', //组织类型（1部门 2公司）
        regionId: this.queryParams.cityId, //所在城市（省市区id）
      }).then((res) => {
        this.belongCompanyList = res.data
      })
    },
    citySelectionChange(val) {
      if (val.length > 0) {
        this.queryParams.region = val[0].pathNodes[0]?.label
        this.queryParams.regionId = val[0].pathNodes[0]?.value
        this.queryParams.provinceName = val[0].pathNodes[1]?.label
        this.queryParams.provinceId = val[0].pathNodes[1]?.value
        this.queryParams.cityName = val[0].pathNodes[2]?.label
        this.queryParams.cityId = val[0].pathNodes[2]?.value
      } else {
        this.queryParams.regionId = null
        this.queryParams.region = null
        this.queryParams.provinceName = null
        this.queryParams.provinceId = null
        this.queryParams.cityId = null
        this.queryParams.cityName = null
      }

      let find = this.belongCompanyList.find((item) => this.queryParams.ascriptionId == item.deptId)

      if (this.queryParams.cityId && find && this.queryParams.cityId != find.regionId.split('/')[1]) {
        this.queryParams.ascription = null
        this.queryParams.ascriptionId = null
      }

      this.belongCompanyList = []
      this.getBelongCompany()
    },

    //归属
    belongChange(val) {
      let find = this.belongCompanyList.find((item) => val == item.deptId)
      if (find) {
        this.queryParams.ascription = find.deptName ?? null
        console.log('belongChange', find)

        this.selIds = [find.areaId, find.regionId && find.regionId.split('/')[0], find.regionId && find.regionId.split('/')[1]]
      } else {
        this.selIds = []
      }
    },
  },
}
</script>

<style lang="scss" scoped>
.pagination-container {
  padding: 0 20px 50px !important;
}

.form-dialog {
  ::v-deep .el-dialog__body .el-form {
    padding: 0 !important;
    margin-bottom: 0 !important;
  }
}

.form-dialog {
  ::v-deep .el-dialog__header {
    padding: 10px 20px;
    border-bottom: 1px solid #dcdfe6;

    .el-dialog__headerbtn {
      top: 15px;
    }
  }

  .box-card {
    margin-bottom: 20px;

    .card-title {
      font-size: 16px;
      position: relative;
      margin-left: 8px;
      padding: 0;
    }

    .card-title::after {
      content: '';
      width: 4px;
      height: 18px;
      background-color: aqua;
      display: block;
      position: absolute;
      left: -12px;
      top: 2px;
    }
  }
}
</style>
